package com.rickpan.dto.request;

import jakarta.validation.constraints.NotNull;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;

/**
 * 生成报告请求DTO
 */
public class GenerateReportRequest {

    @NotNull(message = "报告类型不能为空")
    private ReportType type;

    @NotNull(message = "开始日期不能为空")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    private LocalDate startDate;

    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    private LocalDate endDate;

    // AI生成设置参数
    private String model;
    private Double temperature;
    private Integer maxLength;
    private String style;
    private java.util.List<String> includeContent;

    /**
     * 报告类型枚举
     */
    public enum ReportType {
        DAILY("日报"),
        WEEKLY("周报"),
        MONTHLY("月报");

        private final String description;

        ReportType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    // 构造函数
    public GenerateReportRequest() {}

    public GenerateReportRequest(ReportType type, LocalDate startDate, LocalDate endDate) {
        this.type = type;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    // Getter 和 Setter 方法
    public ReportType getType() {
        return type;
    }

    public void setType(ReportType type) {
        this.type = type;
    }

    public LocalDate getStartDate() {
        return startDate;
    }

    public void setStartDate(LocalDate startDate) {
        this.startDate = startDate;
    }

    public LocalDate getEndDate() {
        return endDate;
    }

    public void setEndDate(LocalDate endDate) {
        this.endDate = endDate;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Double getTemperature() {
        return temperature;
    }

    public void setTemperature(Double temperature) {
        this.temperature = temperature;
    }

    public Integer getMaxLength() {
        return maxLength;
    }

    public void setMaxLength(Integer maxLength) {
        this.maxLength = maxLength;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public java.util.List<String> getIncludeContent() {
        return includeContent;
    }

    public void setIncludeContent(java.util.List<String> includeContent) {
        this.includeContent = includeContent;
    }

    /**
     * 验证日期范围
     */
    public void validateDateRange() {
        if (type == ReportType.DAILY) {
            // 日报只需要开始日期，结束日期应该为空或等于开始日期
            if (endDate != null && !endDate.equals(startDate)) {
                throw new IllegalArgumentException("日报的结束日期应该等于开始日期或为空");
            }
        } else {
            // 周报和月报需要结束日期
            if (endDate == null) {
                throw new IllegalArgumentException(type.getDescription() + "需要指定结束日期");
            }
            if (endDate.isBefore(startDate)) {
                throw new IllegalArgumentException("结束日期不能早于开始日期");
            }
        }
    }

    @Override
    public String toString() {
        return "GenerateReportRequest{" +
                "type=" + type +
                ", startDate=" + startDate +
                ", endDate=" + endDate +
                '}';
    }
}
